# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python

import os
import shutil

class Recipe(recipe.Recipe):
    """
    Contains headers that add workarounds/replacements for GNU libc extensions.
    These have been taken from platform/external/elfutils/bionic-fixup in AOSP
    Currently, it only ships error.h from that set of fixups
    See:
    https://android.googlesource.com/platform/external/elfutils/+/android-4.4.1_r1/bionic-fixup/error.h
    """
    name = 'bionic-fixup'
    version = '4.4.1'
    licenses = [License.Apachev2]
    btype = BuildType.CUSTOM
    stype = SourceType.CUSTOM
    files_devel = ['include/error.h']

    def prepare(self):
        if self.config.target_platform == Platform.LINUX:
            raise InvalidRecipeError(self, "Invalid platform")

    def install(self):
        include_path = os.path.join(self.config.prefix, 'include')
        bionicfixup_path = os.path.join(self.config.recipes_dir, 'bionic-fixup')
        if not os.path.exists(include_path):
            os.makedirs(include_path)
        for f in os.listdir(bionicfixup_path):
            shutil.copy(os.path.join(bionicfixup_path, f), include_path)
